package StudyCode.summary.mycollection;

import java.util.HashMap;
import java.util.Map;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class MergeMaps {
	public static <T> Map<T, Integer> mergeMaps(
			final Map<T, Integer>... maps) {
		final Map<T, Integer> merged = new HashMap<T, Integer>();
		for (final Map<T, Integer> map : maps) {
			for (final Map.Entry<T, Integer> entry : map.entrySet()) {
				if (entry.getValue() != null && entry.getValue() != 0) {
					final Integer curValue = merged.get(entry.getKey());
					merged.put(entry.getKey(),
							curValue == null ? entry.getValue() : curValue
									+ entry.getValue());
				}
			}
		}
		return merged;
	}
}
